package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @Auther: Tangguo
 * @Date: 2023-04-30  13:20
 * @description: TODO
 */
@Mapper
public interface OrderMapper {
    /**
     * @param order:
     * @return void
     * @description 插入订单数据
     */
    void insert(Orders order);

    /**
     * @param orderNumber:
     * @param userId:
     * @return Orders
     * @description  根据订单号和用户id查询订单
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * @param orders:
     * @return void
     * @description 修改订单信息
     */
    void update(Orders orders);

    /**
     * @param ordersPageQueryDTO:
     * @return Page<Orders>
     * @description 调用分页条件查询订单
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * @param id:
     * @return Orders
     * @description 根据用户id查询该用户订单
     */
    @Select("select * from orders where id=#{id} ")
    Orders getById(Long id);


    /**
     * @param id:
     * @return Integer
     * @description 各个状态的订单数量统计
     */
    @Select(" select count(*) from orders where status =#{id}")
    Integer countStatus(Integer id);

    /**
     * 根据状态和下单时间查询订单
     * @param status:
     * @param orderTime:
     * @return List<Orders>
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);


    /**
     * 根据动态条件统计营业额
     * @param map:
     * @return Double
     */
    Double sumByMap(Map map);


    /**
     * 根据动态条件统计订单数量
     * @param map:
     * @return Integer
     */
    Integer countByMap(Map map);

    /**
     * 查询销量排名
     * @param begin:
     * @param end:
     * @return List<GoodsSalesDTO>
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
